package com.example.tms.controller;


import com.example.tms.bean.Piclist;
import com.example.tms.bean.ReturnInfo;
import com.example.tms.mapper.PiclistMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.tms.annotation.*;
@RestController
public class PiclistController {

    private final PiclistMapper piclistMapper;


    @Autowired
    public PiclistController(PiclistMapper piclistMapper) {
        this.piclistMapper = piclistMapper;
    }

    @RequestMapping(value = "/piclist",method = RequestMethod.GET)
    public Piclist getPiclistAll(){
        return piclistMapper.findOne("884eef49c6e94181bba220e8fb7ea3de");
    }

    @MonitorRequest
    @RequestMapping(value = "/piclist",method = RequestMethod.PUT)
    public ReturnInfo updatePiclist(@RequestBody Piclist piclist){
        List<Map<String,Object>>  list = new ArrayList<>();
        Map<String,Object>  map = new HashMap<>();

        if(piclist.getPiclistid()==null||piclist.getPiclistid().equals("")){
            map.put("piclistid","0");
        }
        if(piclist.getJsyb()==null){
            map.put("jsyb","0");
        }
        if(piclist.getJsyh()==null){
            map.put("jsyh","0");
        }
        if(piclist.getJsyz()==null){
            map.put("jsyz","0");
        }
        if(piclist.getZzjsyb()==null){
            map.put("zzsyb","0");
        }
        if(piclist.getZzjsyh()==null){
            map.put("zzsyh","0");
        }
        if(piclist.getZzjsyz()==null){
            map.put("zzsyz","0");
        }
        if(piclist.getClb()==null){
            map.put("clb","0");
        }
        if(piclist.getClh()==null){
            map.put("clh","0");
        }
        if(piclist.getClz()==null){
            map.put("clz","0");
        }
        if(piclist.getWfpclb()==null){
            map.put("wfpclb","0");
        }
        if(piclist.getWfpclh()==null){
            map.put("wfpclh","0");
        }
        if(piclist.getWfpclz()==null){
            map.put("wfpclz","0");
        }
        if(piclist.getYdb()==null){
            map.put("ydb","0");
        }
        if(piclist.getYdz()==null){
            map.put("ydz","0");
        }
        if(piclist.getDdb()==null){
            map.put("ddb","0");
        }
        if(piclist.getDdh()==null){
            map.put("ddh","0");
        }
        if(piclist.getDdz()==null){
            map.put("ddz","0");
        }
        list.add(map);
        if(map.isEmpty()){
            piclistMapper.saveAndFlush(piclist);
            return ReturnInfo.info1("更新成功！");
        }else {
            return ReturnInfo.info1("更新失败！");
        }

    }

}
